<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="汇报时间" prop="time">
      <el-input v-model="dataForm.time" placeholder="汇报时间"></el-input>
    </el-form-item>
    <el-form-item label="班级" prop="department">
      <el-input v-model="dataForm.department" placeholder="班级"></el-input>
    </el-form-item>
    <el-form-item label="汇报人" prop="person">
      <el-input v-model="dataForm.person" placeholder="汇报人"></el-input>
    </el-form-item>
    <el-form-item label="辅导员" prop="object">
      <el-input v-model="dataForm.object" placeholder="辅导员"></el-input>
    </el-form-item>
    <el-form-item label="当前地点" prop="place">
      <el-input v-model="dataForm.place" placeholder="当前地点"></el-input>
    </el-form-item>
    <el-form-item label="是否访问过湖北" prop="visithb">
      <el-input v-model="dataForm.visithb" placeholder="是否访问过湖北"></el-input>
    </el-form-item>
    <el-form-item label="是否接触过湖北人" prop="touchhb">
      <el-input v-model="dataForm.touchhb" placeholder="是否接触过湖北人"></el-input>
    </el-form-item>
    <el-form-item label="" prop="touchsickness">
      <el-input v-model="dataForm.touchsickness" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="当前症状" prop="status">
      <el-input v-model="dataForm.status" placeholder="当前症状"></el-input>
    </el-form-item>
    <el-form-item label="是否就诊" prop="watchdoctor">
      <el-input v-model="dataForm.watchdoctor" placeholder="是否就诊"></el-input>
    </el-form-item>
    <el-form-item label="诊断结果" prop="result">
      <el-input v-model="dataForm.result" placeholder="诊断结果"></el-input>
    </el-form-item>
    <el-form-item label="14日内是否有以上症状" prop="status14">
      <el-input v-model="dataForm.status14" placeholder="14日内是否有以上症状"></el-input>
    </el-form-item>
    <el-form-item label="痊愈几天" prop="recovery">
      <el-input v-model="dataForm.recovery" placeholder="痊愈几天"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          time: '',
          department: '',
          person: '',
          object: '',
          place: '',
          visithb: '',
          touchhb: '',
          touchsickness: '',
          status: '',
          watchdoctor: '',
          result: '',
          status14: '',
          recovery: ''
        },
        dataRule: {
          time: [
            { required: true, message: '汇报时间不能为空', trigger: 'blur' }
          ],
          department: [
            { required: true, message: '班级不能为空', trigger: 'blur' }
          ],
          person: [
            { required: true, message: '汇报人不能为空', trigger: 'blur' }
          ],
          object: [
            { required: true, message: '辅导员不能为空', trigger: 'blur' }
          ],
          place: [
            { required: true, message: '当前地点不能为空', trigger: 'blur' }
          ],
          visithb: [
            { required: true, message: '是否访问过湖北不能为空', trigger: 'blur' }
          ],
          touchhb: [
            { required: true, message: '是否接触过湖北人不能为空', trigger: 'blur' }
          ],
          touchsickness: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '当前症状不能为空', trigger: 'blur' }
          ],
          watchdoctor: [
            { required: true, message: '是否就诊不能为空', trigger: 'blur' }
          ],
          result: [
            { required: true, message: '诊断结果不能为空', trigger: 'blur' }
          ],
          status14: [
            { required: true, message: '14日内是否有以上症状不能为空', trigger: 'blur' }
          ],
          recovery: [
            { required: true, message: '痊愈几天不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/report/report/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.time = data.report.time
                this.dataForm.department = data.report.department
                this.dataForm.person = data.report.person
                this.dataForm.object = data.report.object
                this.dataForm.place = data.report.place
                this.dataForm.visithb = data.report.visithb
                this.dataForm.touchhb = data.report.touchhb
                this.dataForm.touchsickness = data.report.touchsickness
                this.dataForm.status = data.report.status
                this.dataForm.watchdoctor = data.report.watchdoctor
                this.dataForm.result = data.report.result
                this.dataForm.status14 = data.report.status14
                this.dataForm.recovery = data.report.recovery
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/report/report/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'time': this.dataForm.time,
                'department': this.dataForm.department,
                'person': this.dataForm.person,
                'object': this.dataForm.object,
                'place': this.dataForm.place,
                'visithb': this.dataForm.visithb,
                'touchhb': this.dataForm.touchhb,
                'touchsickness': this.dataForm.touchsickness,
                'status': this.dataForm.status,
                'watchdoctor': this.dataForm.watchdoctor,
                'result': this.dataForm.result,
                'status14': this.dataForm.status14,
                'recovery': this.dataForm.recovery
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
